﻿using Caliburn.Micro;
using CommunityToolkit.Mvvm.ComponentModel;
using DataAccess.Toolkit.Entities;
using DataAccess.Toolkit.Services;
using System;
using System.Collections.ObjectModel;
using System.ComponentModel.Composition;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Media.Imaging;
using UI.Toolkit.Interfaces;
using Wpf.Ui.Common;

namespace UI.Toolkit.ViewModels
{
    [Export(typeof(INavigationItem))]
    public class CustomerViewModel : Conductor<Customer>.Collection.OneActive, INavigationItem
    {
        public SymbolRegular Icon { get; set; } = SymbolRegular.People12;
        public override string DisplayName { get; set; } = "Customer";
        public BitmapSource IconImage { get; set; }


        protected override Task OnInitializeAsync(CancellationToken cancellationToken)
        {
            GetDataFromServices();
            return base.OnInitializeAsync(cancellationToken);
        }

        private void GetDataFromServices()
        {
            Items.Clear();
            Items.AddRange(IoC.Get<ICustomerServices>().GetAll());
            ActivateItemAsync(Items.First());
        }

        public override void Refresh()
        {
            GetDataFromServices();
            base.Refresh();
        }

    }
}
